#ifndef __Wtimer_hh__
#define __Wtimer_hh__

/*
  (c) James N. Simone and Fermilab
*/

#include <sys/time.h>

/*
extern "C" {
  struct timeval
  {
    long tv_sec;	// Seconds.
    long tv_usec;	// Microseconds.
  };

  // Structure crudely representing a timezone.
  // This is obsolete and should never be used.
  struct timezone
  {
    int tz_minuteswest;		// Minutes west of GMT.
    int tz_dsttime;		// Nonzero if DST is ever in effect.
  };

  int gettimeofday (struct timeval *tv, struct timezone *tz );
}
*/

class Wtimer
{
public:
  void start ( void )
    {
      gettimeofday ( &_start, static_cast<struct timezone*> ( 0 ) );
    };

  double stop ( void )
    {
      gettimeofday ( &_stop,  static_cast<struct timezone*> ( 0 ) );
      return readout ( );
    };

  double readout ( void )
    {
      long secs = _stop.tv_sec  - _start.tv_sec;
      long usec = _stop.tv_usec - _start.tv_usec;

      return ( (double) secs + 1.0e-6 * (double) usec );
    };

private:
  struct timeval _start;
  struct timeval _stop;
};

#endif
